package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintWriter;
import java.net.Socket;


public class Pinger implements Runnable {
	Socket mySocket;
	BufferedReader br;
	PipedOutputStream pos;
	PrintWriter pw;
	
	public Pinger(Socket socket, PipedInputStream pis){
		mySocket = socket;
		try{
		br = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
		pos = new PipedOutputStream(pis);
		pw = new PrintWriter(pos, false);
		}
		catch (IOException e){
			e.printStackTrace();
		}
	}

	@Override
	public void run() {
		while(true){
			try{
				String line = br.readLine();
				if(!line.equals("ping")){
					pw.println(line);
					pw.flush();
				}
			}
			catch(IOException e){
				e.printStackTrace();
			}
		}
	}

}
